package com.sky.controller.admin;


import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "管理端--订单相关接口")
@RequestMapping("/admin/order")
@RestController("adminOrdersController")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result conditionSearch(OrdersPageQueryDTO dto){
        log.info("订单搜索:{}",dto);
        PageResult pageResult = ordersService.conditionSearch(dto);
        return Result.success(pageResult);
    }

    /**
     *各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO vo = ordersService.statistics();
        return Result.success(vo);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id){
        log.info("查询订单详情:{}",id);
        OrderVO vo = ordersService.details(id);
        return Result.success(vo);
    }

    /**
     * 接单
     * @param orders
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody Orders orders){
        log.info("接单:{}",orders);
        ordersService.confirm(orders);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("派送订单:{}",id);
        ordersService.delivery(id);
        return Result.success();
    }
    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation(value = "完成订单")
    public Result complete(@PathVariable Long id){
        log.info("完成订单：{}",id);
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 取消订单
     * @param dto
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        log.info("取消订单：{}",dto);
        ordersService.cancel(dto);
        return Result.success();
    }

    /**
     * 拒单
     * @param dto
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单：{}",dto);
        ordersService.rejection(dto);
        return Result.success();
    }
}
